﻿using System;
using System.Text;
using System.ServiceModel;
using System.ComponentModel;
using Sinacor.Infra.UI.Common;
using System.Collections.Generic;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Corretagem.Communication.Bovespa.Corretagem.DescontoCliente;

namespace Sinacor.UI.Bovespa.Corretagem.Communication
{
    public class DescontoCliente : BaseCommunication
    {
        #region Construtor

        public DescontoCliente(SessionInformation sessionInformation)
            : base(sessionInformation)
        {
        }

        #endregion

        #region AlterarDescontoCliente

        public void AlterarDescontoCliente(Model.DescontoCliente request)
        {
            IDescontoCliente servico = null;

            try
            {
                using (ServiceInstance<IDescontoCliente> service = new ServiceInstance<IDescontoCliente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.AlterarDescontoCliente((new Translator.ModelToDataContract.DescontoCliente().ToDescontoClienteRequest(request)));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

        }

        #endregion

        #region AlterarDescontoClientes

        public void AlterarDescontoClientes(ModelCollection<Model.DescontoCliente> request)
        {
            IDescontoCliente servico = null;

            try
            {
                using (ServiceInstance<IDescontoCliente> service = new ServiceInstance<IDescontoCliente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.AlterarDescontoClientes((new Translator.ModelToDataContract.DescontoCliente().ToDescontoClienteRequest(request)));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

        }

        #endregion

        #region ConsultarDescontosClientes

        public ModelCollection<Model.DescontoCliente> ConsultarDescontosClientes(Model.Parameter.FiltroDescontoCliente request)
        {
            IDescontoCliente servico = null;
            ModelCollection<Model.DescontoCliente> descontoCliente = new ModelCollection<Sinacor.UI.Bovespa.Corretagem.Model.DescontoCliente>(); 
            try
            {
                using (ServiceInstance<IDescontoCliente> service = new ServiceInstance<IDescontoCliente>())
                {

                    servico = service.TryGetInstance(this.Session);
                    descontoCliente = new Translator.DataContractToModel.DescontoCliente().ToDescontoCliente( 
                                                       servico.ConsultarDescontosClientes(
                                                        new Translator.ModelToDataContract.DescontoCliente().ToFiltroDescontoClienteRequest(request)));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }
            return descontoCliente; 
        }

        #endregion

        #region ExcluirDescontoCliente

        public void ExcluirDescontoCliente(Model.Parameter.FiltroDescontoCliente request)
        {
            IDescontoCliente servico = null;

            try
            {
                using (ServiceInstance<IDescontoCliente> service = new ServiceInstance<IDescontoCliente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.ExcluirDescontoCliente((new Translator.ModelToDataContract.DescontoCliente().ToFiltroDescontoClienteRequest(request)));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

        }

        #endregion

        #region ExcluirDescontosClientes

        public void ExcluirDescontoClientes(ModelCollection<Model.Parameter.FiltroDescontoCliente> request)
        {
            IDescontoCliente servico = null;

            try
            {
                using (ServiceInstance<IDescontoCliente> service = new ServiceInstance<IDescontoCliente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.ExcluirDescontoClientes((new Translator.ModelToDataContract.DescontoCliente().ToFiltroDescontoClienteRequest(request)));
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

        }

        #endregion

        #region ExecutarTransacoesDescontoCliente

        public void ExecutarTransacoesDescontoCliente(ModelCollection<Model.DescontoCliente> inclusaoList
                                              , ModelCollection<Model.Parameter.FiltroDescontoCliente> exclusaoList
                                              , ModelCollection<Model.DescontoCliente> alteracaoList
                                              )
        {
            IDescontoCliente servico = null;

            try
            {
                using (ServiceInstance<IDescontoCliente> service = new ServiceInstance<IDescontoCliente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.ExecutarTransacoesDescontoCliente(new Translator.ModelToDataContract.DescontoCliente().ToDescontoClienteRequest(inclusaoList)
                                                      , new Translator.ModelToDataContract.DescontoCliente().ToFiltroDescontoClienteRequest(exclusaoList)
                                                      ,new Translator.ModelToDataContract.DescontoCliente().ToDescontoClienteRequest(alteracaoList)
                                                      );
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

        }

        #endregion

        #region IncluirDescontoCliente

        public void IncluirDescontoCliente(Model.DescontoCliente request
                                             
                                              )
        {
            IDescontoCliente servico = null;

            try
            {
                using (ServiceInstance<IDescontoCliente> service = new ServiceInstance<IDescontoCliente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.IncluirDescontoCliente ( new Translator.ModelToDataContract.DescontoCliente().ToDescontoClienteRequest(request)
                                                      );
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

        }

        #endregion

        #region IncluirDescontoClientes

        public void IncluirDescontoClientes(ModelCollection<Model.DescontoCliente> request

                                              )
        {
            IDescontoCliente servico = null;

            try
            {
                using (ServiceInstance<IDescontoCliente> service = new ServiceInstance<IDescontoCliente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.IncluirDescontoClientes(new Translator.ModelToDataContract.DescontoCliente().ToDescontoClienteRequest(request)
                                                      );
                }
            }
            catch (Exception ex)
            {
                HandleFault(ex);
            }

        }

        #endregion

    }
}
